<template>
  <div class="movie">
    <moliVideo :videoList="videoList" @toDetails="details"></moliVideo>
    <bottoms></bottoms>
  </div>
</template>

<script>
  import moliVideo from '@/components/moliVideo/index'
  import bottoms from '@/components/reachBottom/index'
  export default {
    components:{
      moliVideo,
      bottoms
    },
    mpType: 'page',
    data() {
      return {
        videoList: [], //影视学堂列表
        loadingEnd:{
          moduleOne: false,
        },
        totalPage: 1,
        currentPage: 1
      }
    },
    methods: {
      details(id){
		  uni.navigateTo({
		  	url: '/movie/detail?id='+id
		  })
      },
      getMovieList(){
        this.$ajax
          .post(this.$api.movieList,{page: this.currentPage})
          .then(res => {
            this.videoList.push(...res.data);
            this.loadingEnd.moduleOne = true
            this.totalPage = res.total_page
            if(res.total_count === 0){
              this.$store.dispatch("changeIsEmpty", true);
            } else {
              this.$store.dispatch("changeIsEmpty", false);
            }
          })
          .catch(err => {
            this.loadingEnd.moduleOne = true
            uni.showToast({
              title: err,
              icon: 'none',
              duration: 2000
            })
          });
      },
      viewLoad(){
        this.$store.dispatch("changeIsMore", false);
        this.$store.dispatch("changeIsEnd", false);
        this.$store.dispatch("changeIsEmpty", false);
        this.currentPage = 1
        this.videoList = []
        this.loadingEnd = {
          moduleOne: false,
        };
        uni.showLoading({
          title: '加载中',
          mask: true
        });
        this.getMovieList();
      }
    },
    computed:{
      hideLoading(){
        if(this.loadingEnd.moduleOne){
          setTimeout(function(){
            uni.hideLoading()
            }, 800)
        }
      }
    },
    onPullDownRefresh(){
      this.viewLoad()
      uni.stopPullDownRefresh() //停止下拉刷新
    },
    onReachBottom(){
      if(this.totalPage > this.currentPage){
        this.$store.dispatch("changeIsMore", true);
        this.$store.dispatch("changeIsEnd", false);
        this.currentPage++
        this.getMovieList();
      } else {
        this.$store.dispatch("changeIsEnd", true);
        this.$store.dispatch("changeIsMore", false);
      }
    },
	onShareAppMessage(res){
	  ﻿this.$common.share()
	},
    onLoad() {
      uni.showShareMenu({
        withShareTicket: true
      })
      this.viewLoad()
    }
  }
</script>

<style scoped>
</style>
